package com.labot.webapp.action;

import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;

import com.labot.dto.InfoDto;

/**
 * Action for facilitating User Management feature.
 */
public class InfoAction extends BaseAction {
    private static final long serialVersionUID = 6776548938712115191L;
    
    private List<InfoDto> properties = new ArrayList<InfoDto>();

    /**
     * Default: just returns "success"
     *
     * @return "success"
     */
    public String execute() {
        return SUCCESS;
    }
    
    public String cancel() {
    	return CANCEL;
    }


    /**
     * Fetch all Configs from database and put into local "configs" variable for retrieval in the UI.
     *
     * @return "success" if no exceptions thrown
     */
    public String list() {
    	Set<Entry<Object, Object>> set = System.getProperties().entrySet();
        for (Entry<Object, Object> entry : set) {
            String key = entry.getKey().toString();
            String value = entry.getValue().toString();
            value = value.replaceAll(";", ";\n");
            value = value.replaceAll(",", ",\n");
//            value = value.replaceAll("\n", "\\\\n");
            properties.add(new InfoDto(key,value));
        }
        
        return SUCCESS;
    }

	public List<InfoDto> getProperties() {
		return properties;
	}

	

}
